package com.four.service.impl;

import com.four.entity.Dept;
import com.four.mapper.DeptMapper;
import com.four.service.DeptService;
import com.four.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description:
 * @author:LiWei
 * @date:2022年10月13日2 0:10
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;

    @Override
    public Result selectAll() {
        List<Dept> depts = deptMapper.selectAll();
        return new Result(200,"查询所有部门",depts);
    }

    @Override
    public Result add(Dept record) {
        int insert=deptMapper.insert(record);
        return new Result(200,"添加部门",insert);
    }

    @Override
    public Result delete(int id) {
        int delete=deptMapper.deleteByPrimaryKey(id);
        return new Result(200,"删除部门成功",delete);
    }

    @Override
    public Result update(Dept record) {
        int update=deptMapper.updateByPrimaryKeySelective(record);
        return new Result(200,"修改部门成功",update);
    }

    @Override
    public Result updateStatus(Dept deptId) {
        if (deptId.getDeptStatus()==1){
            deptId.setDeptStatus(0);
        }else {
            deptId.setDeptStatus(1);
        }
        int i = deptMapper.updateStatus(deptId);
        return new Result(200,"修改部门状态成功",i);
    }




}
